@include("user.head")
	<!-- 公共头部 -->

	<div id="content_person">
	<div class="row">
	<div class="col-xs-3">
		@include("user.uc.navigation")
	</div>
	<div class="col-xs-9">
		<div class="panel panel-default">
		  <div class="panel-heading">
		    <h3 class="panel-title">编辑基本信息</h3>
		  </div>
		  <div class="panel-body">
				<form class="form-horizontal" id="Form" method="post" action="edit_groupinfo/update">
				  <fieldset>
				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">单位名称</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="company_name" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">组织机构代码</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="group_code" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">联系人</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="contact_person" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">联系人电话</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="contact_number" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label for="select" class="col-xs-3 control-label">注册地址</label>
				      <div class="col-xs-6">

				        <select class="form-control select_size selects" name="province" id="province">
				          <option value="-1">请选择</option>
							@include("user.uc.province_option")
				        </select>
				        <select class="form-control select_size selects" name="city" id="city">
				          <option value="-1">请选择</option>
				        </select>
				        <select class="form-control select_size selects" name="area" id="area">
				          <option value="-1">请选择</option>
				        </select>
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">详细地址</label>
				      <div class="col-xs-6">
					  	<input class="form-control input_size" name="address" placeholder="" type="text">
					  </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">邮政编码</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="zcode" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">传真</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="fax" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">联系人邮箱</label>
				      <div class="col-xs-6">
				        <input class="form-control input_size" name="email" placeholder="" type="text">
				      </div>
				    </div>

				    <div class="form-group">
				      <label class="col-xs-3 control-label label_size">营业执照副本</label>
				      <div class="col-xs-6">
				        <a href="javascript:;" class="file btn btn-primary">上传
				            <input type="file" name="imgFile" name="" id="copy">
				            <input type="hidden" name="regist_copy" id="copyFileName">
				        </a><span id="copyName"></span>
				      </div>
				    </div>

				    <div class="form-group">
				    	<label class="col-xs-3 control-label no_padding_right">LOGO:</label>
				    	<div class="col-xs-6">
				    		<a href="javascript:;" class="file btn btn-primary">上传
				    			<input type="file" name="imgFile" id="logo">
				    			<input type="hidden" name="logo" id="logoFileName">
				    		</a>
				    		<span id="logoName"></span>
				    	</div>
				    </div>

			    	<div class="form-group">
			          <label class="col-xs-3 control-label no_padding_right">描述:</label>
			          <div class="col-xs-6">
			            <textarea class="form-control text_size" name="description" rows="3"></textarea>
			            <span class="help-block"></span>
			          </div>
			        </div>

				    <div class="form-group">
				      <label for="textArea" class="col-xs-3 control-label label_size">简介</label>
				      <div class="col-xs-9">
					    	<div id="container" name="induction" style="height:500px;"></div>
				      </div>
				    </div>

				    <div class="form-group">
				      <div class="col-xs-12 text-center">
				        <button type="button" id="sub" class="btn btn-primary">保存修改</button>
				      </div>
				    </div>
				  </fieldset>
				</form>
			</div>
		</div>
	</div>
	</div>
	</div>

	<!-- 公共底部 -->
	@include("user.footer")
	@include("user.common")
	<!-- 公共底部 -->


</body>
<script type="text/javascript">

var ue = UE.getEditor('container');;

var isasync = false;
$.get('edit_groupinfo/list', function(data){
	if(data.success){
		$('input[name=company_name]').val(data.company_name);
		$('input[name=legal_person]').val(data.legal_person);
		$("select[name='province']").val(data.province);
		$("select[name='province']").change();
		$("select[name='city']").val(data.city);
		$("select[name='city']").change();
		$("select[name='area']").val(data.area);

		$('input[name=address]').val(data.address);
		$('input[name=zcode]').val(data.zcode);
		$('input[name=code]').val(data.code);
		$('input[name=fax]').val(data.fax);
		$('input[name=group_code]').val(data.group_code);
		$('input[name=contact_person]').val(data.contact_person);
		$('input[name=contact_number]').val(data.contact_number);
		$('input[name=email]').val(data.email);
		$('input[name=regist_copy]').val(data.regist_copy);
		$('input[name=logo]').val(data.logo);
		$('textarea[name="description"]').val(data.description);
		ue.ready(function(){
			ue.setContent(decodeURIComponent(data.induction));
		});

		isasync = true;
	}else{

	}
})


$("#province").change(function(){
	var pid = $(this).val();
	$.ajax({
		url : '<% url("uc/address/getarea") %>',
		type : "get",
		async : isasync,
		data : {pid :pid},
		success:function(data){
			var str = '<option value="-1">请选择</option>';
			$.each(data.area,function(k, v){
				str += '<option value="'+v.area_id+'">'+v.area_name+'</option>';
			})
			$("#city").html(str);
			$("#area").html('<option value="-1">请选择</option>');
		}
	})
})

$("#city").change(function(){
	var pid = $(this).val();
	$.ajax({
		url : '<% url("uc/address/getarea") %>',
		type : 'get',
		async : isasync,
		data : {pid : pid},
		success : function(data){
			var str = '<option value="-1">请选择</option>';
			$.each(data.area,function(k, v){
				str += '<option value="'+v.area_id+'">'+v.area_name+'</option>';
			})
			$("#area").html(str);
		}
	})
})

$('#copy').AjaxFileUpload({
	path : "<% url('uc/user/upload') %>",
	onComplete : function(filename){
			$("#copyName").html(filename.filename);
			$("#copyFileName").val(filename.filename);
		}
	});

$('#logo').AjaxFileUpload({
	path : "<% url('uc/user/upload') %>",
	onComplete : function(filename){
			$("#logoName").html(filename.filename);
			$("#logoFileName").val(filename.filename);
	}
});

$("#sub").click(function(){


	var company_name = $("input[name='company_name']").val().trim();
	var group_code = $("input[name='group_code']").val().trim();
	var contact_person = $("input[name='contact_person']").val().trim();
	var contact_number = $("input[name='contact_number']").val().trim();
	var province = $("select[name='province']").val().trim();
	var city = $("select[name='city']").val().trim();
	var area = $("select[name='area']").val().trim();

	var address = $("input[name='address']").val().trim();
	var logo = $("input[name='logo']").val().trim();
	var regist_copy = $("input[name='regist_copy']").val().trim();
	var induction = encodeURIComponent(ue.getContent());
	var email = $("input[name='email']").val().trim();
	var zcode = $("input[name='zcode']").val().trim();
	var fax = $("input[name='fax']").val().trim();
	var description = $("textarea[name='description']").val().trim();


	if (company_name == '' || province < 1 || city < 1 || address == '' ||
		group_code == '' || contact_person == '' || contact_number == '' || email == '' || induction == '' || logo == '')
	{
		warning('','必填信息不能为空');
		return false;
	}

	$.post("edit_groupinfo/update", {
	company_name : company_name,
	province : province,
	city : city,
	area : area,
	address : address,
	contact_person : contact_person,
	contact_number : contact_number,
	email : email,
	group_code : group_code,
	regist_copy : regist_copy,
	induction : induction,
	fax : fax,
	zcode : zcode,
	logo : logo,
	description : description
	},function (data){
		if(data.success){
			success("", "提交成功");
			setTimeout(function(){
				window.location.href="groupinfo";
			}, 2000)
		}else{
			warning("", data.msg);
		}
	})
})
</script>
</html>